import type { TodoItem } from '@/types/todo';
import http from '@/utils/http';

export const TodoService = {
  getTodos: async (): Promise<TodoItem[]> => {
    const response = await http.get('/todos');
    return response.data;
  },

  addTodo: async (text: string): Promise<TodoItem> => {
    const response = await http.post('/todos', { text });
    return response.data;
  },

  toggleTodo: async (id: number): Promise<TodoItem> => {
    const response = await http.put(`/todos/${id}/toggle`);
    return response.data;
  },

  removeTodo: async (id: number): Promise<void> => {
    await http.delete(`/todos/${id}`);
  },
};
